package com.wzcl.app.service.impl;

import com.wzcl.app.dao.model.SysDict;
import com.wzcl.app.dao.repository.SysDictRepository;
import com.wzcl.app.model.vo.SysDictVo;
import com.wzcl.app.service.SysDictService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Log4j2
@Service
public class SysDictServiceImpl implements SysDictService {

    @Autowired
    private SysDictRepository repository;

    @Override
    @Cacheable(value = "SysDict", keyGenerator = "cacheKeyGenerator")
    public SysDictVo getSysDictByKeyName(String keyName) {
        SysDict sysDict = repository.findByKeyName(keyName);
        if (sysDict != null) {
            return SysDictVo.create(sysDict);
        }
        return null;
    }

    @Override
    public List<SysDict> getSysDictList() {
        return repository.findAll();
    }
}
